<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use App\Models\Grade;

class GradeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '等级管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Grade);

        $grid->column('id', __('Id'));
        $grid->column('grade', __('等级'));
        $grid->column('detailed', __('详细'));
        // $grid->column('path', __('路径'));
        // $grid->column('sort', __('排序'));
        // $grid->column('url', __('跳转url'));
        $grid->column('state', __('状态'))->display(function ($status) {
            return config('conf.status')[$status];
        });
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Grade::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('grade', __('Title'));
        $show->field('detailed', __('Content'));
        $show->field('state', __('Status'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Grade);

        $form->text('grade', __('等级'));
        $form->text('detailed', __('详情'));
        $form->select('state', __('状态'))->options(config('conf.status'));
        $form->datetime('created_at', __('创建时间'));

        return $form;
    }
}
